﻿package  {
	
	public class Logic {

		public static var reelLines:int = 9;
		public static var reelBets:Array = [0.01,0.05,0.1,0.5,1,2,5,10];		
		
		
		
		
		
		
		
		
		public static var winLineBack = false;

		//TODO: 2types of scatters anims, one is inside wheel, second inside reels
		//	0	3	6	9	12
		//	1	4	7	10	13
		//	2	5	8	11	14

		public static var wildNumber = 12; //symId

		public static var lineColors:Array = [0x34FEDD,0xE3DC1C,0xcccccc,0xcccccc,0xcccccc,0xcccccc,0xcccccc,0xcccccc,0xcccccc,];
		public static var winLines:Array = 
		[
		 	[1,4,7,10,13], //line1
			[0,3,6,9,12], //line2
			[2,5,8,11,14], //line3
			[0,4,8,10,12], //line4
			[2,4,6,10,14], //line5
			[1,3,6,9,13], //line6
			[1,5,8,11,13], //line7
			[0,3,7,11,14], //line8
			[2,5,7,9,12], //line9
		];
		
		public static var winSymbols:Array = 
		[
			[0,0,5,7,9,13], //symbol1,
			[0,0,5,7,9,13],	//symbol2
			[0,0,5,7,9,13],	//symbol3
			[0,0,5,7,9,13],	//symbol4
			[0,0,5,7,9,13],	//symbol5
			[0,0,5,7,9,13],	//symbol6
			[0,0,5,7,9,13],	//symbol7
			[0,0,5,7,9,13],	//symbol8
			[0,0,5,7,9,13],	//symbol9
			[0,0,5,7,9,13],	//symbol10
			[0,0,5,7,9,13],	//symbol11
			[0,0,5,7,9,13],	//symbol12
		];
		public static var wheelIcons:Array = 
		[
			'icon_s_1','icon_s_2','icon_s_3','icon_s_4','icon_s_5','icon_s_6',
			'icon_s_7','icon_s_8','icon_s_9',
			'icon_s_10','icon_s_11','icon_s_12'
		];
		public static var animClipsSymbols:Array = 
		[
			['s10','anim_bonus'],
			['s11','anim_scatter'],
			['s12','anim_wild'],
		]
		
		public static var winAnimSymbols:Array =
		[
			[0,0],
			[0,0],
			[0,0],
			[0,0],
			[0,0],
			[0,0],
			[0,0],
			[0,0],
			[0,0],
			[1,'s10',0,4],
			[1,'s11',0,4],
			[1,'s12',0,4],
		
		];





























		public function Logic() {
			super();
			// constructor code
		}
		
		//GAME LOGIC
		public static function calculateWins(lines:int ,numbers:Array):Array
		{
			var ret:Array = new Array();
			
			var save_arr:Array;
			var i:int;
			var j:int;
			
			var counts:int;
			var lsymbol:int;
			var winnigs:Number;

			var line_info:Array;

			for(i=0;i<lines;i++)
			{
				line_info = Logic.winLines[i];
				//forward calc
				counts = 0;
				lsymbol = 0;
				winnings = 0;
				
				for(j=0;j<line_info.length;j++)
				{
					if(lsymbol == 0) //just started
					{
						lsymbol = numbers[line_info[j]];
						counts++;
						continue;
					}
					if(numbers[line_info[j]] == Logic.wildNumber)
					{
						counts++;
						continue;
					}
					if(lsymbol == Logic.wildNumber) //line starts from wild but now not wild
					{
						lsymbol = numbers[line_info[j]];
						counts++;
						continue;
					}
					if(lsymbol == numbers[line_info[j]])
					{
						counts++;
						continue;
					}
					break;
				}
				//calulate by symbols;
				showtime = 1;
				winnings = Logic.winSymbols[lsymbol-1][counts];
				if(winnings > 0)
				{
					save_arr = new Array();
					save_arr.push(i+1); //first line !1! symbols '0'
					save_arr.push(1); //extra
					save_arr.push(winnings); //win amount;
					save_arr.push(showtime); //based time of explain animation;
					//save to [Line,Symbols]
					for(j=0;j<counts;j++)
					{
						save_arr.push(line_info[j]);
					}
					ret.push(save_arr);
				}
			}
			
			return ret;
		}
		
		

	}
	
}
